package com.mkx.orderedlist.skiplist;

/**
 * 跳表节点类
 * @param <K> 键类型
 * @param <V> 值类型
 */
class SkipListNode<K extends Comparable<K>, V> {
    K key;
    V value;
    SkipListNode<K, V>[] forward; // 存储指向各层下一个节点的引用
    
    /**
     * 构造函数
     * @param key 键
     * @param value 值
     * @param level 节点的层数
     */
    @SuppressWarnings("unchecked")
    SkipListNode(K key, V value, int level) {
        this.key = key;
        this.value = value;
        this.forward = (SkipListNode<K, V>[]) new SkipListNode[level + 1]; // level从0开始
        // 初始化所有forward指针为null
        for (int i = 0; i <= level; i++) {
            forward[i] = null;
        }
    }
}
